/*
 * @Author: 飞越疯人院 353362604@qq.com
 * @Date: 2022-09-13 13:42:20
 * @LastEditors: 飞越疯人院 353362604@qq.com
 * @LastEditTime: 2022-12-28 15:20:39
 * @FilePath: \adminstration\src\Common\Router\MenuNavList\Environmental\EnvironmentData.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

import qs from 'qs'
import axios from 'axios'
import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton, ExecuteButton, MoreActionsButton } from '../Common/options'

export const Sample = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        type: '试验事务',
        pageSize: 10,
        params: { pageIndex: 1, OSendTime: 'desc@1' },
        get: API_LIST()[`get${url}GetSampleList`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission.findIndex(v => v.uuid === '354cf8bc-05b3-4321-b10e-5cc3af8c6e07') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'Sample' },
            {
                dataIndex: 'sendTime',
                title: '送检日期',
                valueType: 'Date',
                showTime: true,
                rules: true,
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'status',
                title: '检测状态',
                valueType: 'select',
                valueEnum: BuiltInData.SampleStatus,
                rules: true,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            {
                dataIndex: 'standardModifyNo',
                title: '程序文件编号',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'taskNo',
                title: '任务单编号',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                width: 130,
            },
            {
                dataIndex: 'delegateNo',
                title: '委托书编号',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
                hideInSearch: true,
                width: 130,
            },
            {
                dataIndex: 'clientOrganization',
                title: '委托单位',
                valueType: 'input',
                rules: true,
                width: 250,
            },
            {
                dataIndex: 'engineeringName',
                title: '工程名称',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'engineeringPurpose',
                title: '工程部位/用途',
                valueType: 'input',
                hideInSearch: true,
                width: 150,
            },
            {
                dataIndex: 'sourceType',
                title: '来样方式',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'testRequirement',
                title: '检验要求',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 300,
            },
            {
                dataIndex: 'testBasis',
                title: '试验依据',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'judgeBasis',
                title: '判定依据',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'securityLevel',
                title: '保密要求',
                valueType: 'input',
                hideInSearch: true,
                rules: true,
                width: 300,
            },
            {
                dataIndex: 'sampleReceiveStatus',
                title: '样品接收情况',
                valueType: 'input',
                hideInSearch: true,
                width: 300,
            },
            {
                dataIndex: 'sampleStatus',
                title: '样品状态',
                valueType: 'input',
                hideInSearch: true,
                width: 300,
            },
            {
                dataIndex: 'sampleAdministrator',
                title: '样品管理员',
                valueType: 'input',
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'sampleReceiver',
                title: '样品领取人',
                valueType: 'input',
                hideInSearch: true,
                width: 200,
            },
            {
                dataIndex: 'testRoom',
                title: '试验检测室',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'otherAttachment',
                title: '其他附件',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'receivingReport',
                title: '领取报告方式',
                valueType: 'input',
                width: 200,
            },
            {
                dataIndex: 'paymentMethod',
                title: '付款方式',
                valueType: 'input',
                width: 200,
            },
            commonTableList.StartTime,
            commonTableList.EndTime,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 380,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { status, uuid } = record
                    return [
                        Permission.findIndex(v => v.uuid === 'd6e76d2d-6b64-4891-9ac8-9cbac2c91f2b') !== -1 &&
                            status === 0 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="开始检测"
                                    url="posSampleChangeStatus"
                                    path={[uuid, `?${qs.stringify({ uuid, status: 1 })}`]}
                                    tips="开始检测样品!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'd6e76d2d-6b64-4891-9ac8-9cbac2c91f2b') !== -1 &&
                            status === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="two"
                                    title="完成检测"
                                    url="posSampleChangeStatus"
                                    path={[uuid, `?${qs.stringify({ uuid, status: 2 })}`]}
                                    tips="样品检测完成!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'd6e76d2d-6b64-4891-9ac8-9cbac2c91f2b') !== -1 &&
                            status === 2 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="thr"
                                    title="重新检测"
                                    danger={true}
                                    url="posSampleChangeStatus"
                                    path={[uuid, `?${qs.stringify({ uuid, status: 1 })}`]}
                                    tips="重新检测样品!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === 'fb1e77e0-e8bf-4a41-8532-2123c338745d') !== -1 && (
                            <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />
                        ),
                        Permission.findIndex(v => v.uuid === '4576f81a-a111-4ed5-b9ed-b521594d5a98') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),

                        <MoreActionsButton
                            key="more"
                            title="更多操作"
                            data={{
                                record,
                                Permission,
                                OptionsEvent,
                                header: data.columns,
                                SampleEnclosure: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '来样信息管理',
                                    modal: 'TableList',
                                },
                                SampleParameter: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '配置检测参数',
                                    modal: 'TableList',
                                },
                                SampleAddParameter: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '添加检测数据',
                                    modal: 'TableList',
                                },
                                SampleReport: {
                                    type: 'OpenTwoRouter',
                                    smallTitle: '最终报告管理',
                                    modal: 'TableList',
                                },
                                LabPowerAttorney: {
                                    type: 'ExportExcel',
                                    api: API_LIST()['getLabPowerAttorney'],
                                },
                                LabAssignmentBook: {
                                    type: 'ExportExcel',
                                    api: API_LIST()['getLabAssignmentBook'],
                                },
                            }}
                            items={[
                                Permission.findIndex(v => v.uuid === '3f334abb-fd34-499c-a022-ca30ba4ad4a4') !== -1 && {
                                    key: 'SampleEnclosure',
                                    label: '1来样信息管理',
                                },
                                Permission.findIndex(v => v.uuid === '1f74b730-6372-448e-998b-b12a9de6c226') !== -1 && {
                                    key: 'SampleParameter',
                                    label: '2配置检测参数',
                                },
                                Permission.findIndex(v => v.uuid === 'fdf3022c-e175-4599-955c-a4d5760c2545') !== -1 && {
                                    key: 'LabPowerAttorney',
                                    label: '3下载委托书',
                                },
                                Permission.findIndex(v => v.uuid === '3be76b1e-ddb1-4155-b42f-25a31784c44f') !== -1 && {
                                    key: 'LabAssignmentBook',
                                    label: '4下载任务单',
                                },
                                Permission.findIndex(v => v.uuid === 'c3afa8b7-95c6-45e4-b0f8-ce611413bbba') !== -1 && {
                                    key: 'SampleAddParameter',
                                    label: '5添加检测数据',
                                },
                                Permission.findIndex(v => v.uuid === '4eb390da-9966-4a3c-a529-524e519b91f6') !== -1 && {
                                    key: 'SampleReport',
                                    label: '6最终报告管理',
                                },
                            ]}
                        />,
                    ]
                },
            },
        ],
    }
    const { data: init } = await axios.get(API_LIST()['getSamplePreinstallList'])
    data.initialValues = init
    return data
}
